import { createRouter, createWebHistory } from "vue-router";

const routes = [
    {
        path: "/",
        component: () => import("@/view/table/index.vue"),
    },
    {
        path: "/table",
        component: () => import("@/view/table/index.vue"),
    },
    {
        path: "/editTable",
        component: () => import("@/view/table/edit.vue"),
    },
    {
        path: "/setConfig",
        component: () => import("@/view/setConfig/table.vue"),
    },
    {
        path: "/condition",
        component: () => import("@/view/condition/index.vue"),
    },
    {
        path: "/scanToN",
        component: () => import("@/view/scanToN/scanToN.vue"),
    },
    {
        path: "/switchPage",
        component: () => import("@/view/switchPage/index.vue"),
    },
    {
        path: "/:pathMatch(.*)*",
        // 解决打包后白屏
        beforeEnter: (to, from, next) => {
            if (to.path.startsWith("/")) {
                next("/");
            } else {
                next(false); // 阻止导航
            }
        },
    },
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router;